<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="../js/vue.js"></script>
    <title>Document</title>
</head>
<body>
    <div id="root">
        <h2>{{name}}</h2>
        <h2>当前n的值：<span v-text="n"></span></h2>
        <h2>放大10倍n的值：<span v-big="n"></span></h2>
        <input type="text" v-focus-bind="n">

        <button @click="n++">点击+1</button>
    </div>

    <div id="root2">
        <h2>root2当前n的值：<span v-text="n"></span></h2>
        <h2>放大10倍n的值：<span v-big="n"></span></h2>
        <button @click="n++">点击+1</button>
    </div>

    <script>

        Vue.directive('big', function(element, binding) {
            element.innerText = binding.value*10;
        })

        new Vue({
            el: '#root',
            data: {
                name: '自定义指令directives',
                n: '1'
            },
            directives: {
                "focus-bind": {
                    bind(element, binding) {  // 绑定时
                        console.log('focus-bind', binding)
                        element.value = binding.value;
                    },
                    inserted(element, binding) {  // 被插入页面时
                        console.log('focus-inserted', binding)
                        element.value = binding.value;
                        element.focus()
                    },
                    update(element, binding) {  // 所在模板被重新解析时调用
                        console.log('focus-update', binding)
                        element.value = binding.value;
                        // element.focus()
                    }
                }
            }
        })
        new Vue({
            el: '#root2',
            data: {
                n: 10,
            }
        })
    </script>
</body>
</html>